'''
Created on Jan 30, 2012

@author: talamoig
'''

from whale.utils.Configurable import Configurable
import collections

class Plugin(object):
    '''
    Base class from which every WHALE plugin must inherit.
    '''

    descr=None
    
    def setDescription(self,descr):
        self.descr=descr

    def getDescription(self):
        return self.descr

    def getItem(self,item):
        return self.configurable.getItem(item)

    def setupConfig(self,configfile,section=None,description=None):
        if section==None:
            section=self.__class__.__name__
        self.configurable=Configurable(configfile,section)
        self.descr=None
        if description:
            self.setDescription(description)

    def flatten(self,x):
        if isinstance(x, collections.Iterable):
            return [a for i in x for a in self.flatten(i)]
        else:
            return [x]
  
                
